<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('终端划拨记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 120px">目标服务商编号：</label>
                                <input type="text" name="agentTarNum"/>
                            </li>
                            <li>
                                <label style="width: 120px">目标服务商名称：</label>
                                <input type="text" name="agentTarName"/>
                            </li>
                            <li>
                                <label style="width: 120px">类型：</label>
                                <select name="type">
                                    <option value="">所有</option>
                                    <option value="0">划入</option>
                                    <option value="1">划出</option>
                                    <option value="2">我的返还</option>
                                    <option value="3">下级返还</option>
                                    <option value="4">总后台撤机</option>
                                    <option value="5">发货划拨</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px">批次号：</label>
                                <input type="text" name="serial"/>
                            </li>
                            <li>
                                <label style="width: 120px">SN编号：</label>
                                <input type="text" name="params[sn]"/>
                            </li>
                            <li>
                                <label style="width: 120px">操作服务商名称：</label>
                                <input type="text" name="addName"/>
                            <li>
                                <label style="width: 120px">操作服务商编号：</label>
                                <input type="text" name="addNo"/>
                            </li>
                            <li class="select-time">
                                <label style="width: 120px;">申请日期：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始日期" name="params[beginAddTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束日期" name="params[endAddTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="downloada()" shiro:hasPermission="terminal:record:downloada">
                    <i class="fa fa-plus"></i> 机具划拨模板下载
                </a>
                <a class="btn btn-success" onclick="$.operate.add(700,1200)" shiro:hasPermission="terminal:record:add">
                    <i class="fa fa-plus"></i> 划拨
                </a>
                <a class="btn btn-success" onclick="revoke()" shiro:hasPermission="terminal:record:revoke">
                    <i class="fa fa-plus"></i> 撤机
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('terminal:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('terminal:record:remove')}]];
        var prefix = ctx + "terminal/record";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "终端划拨记录",
                columns: [
                {
                    field: 'agentTarNum',
                    title: '目标服务商编号'
                },
                {
                    field: 'agentTarName',
                    title: '目标服务商名称'
                },
                {
                    field: 'type',
                    title: '申请类型',
                    formatter: function (value, row, index) {
                        if (row.type == 0 ){
                            return '<span style="color: blue">划入</span>';
                        } else if(row.type == 1 ){
                            return '<span style="color: green">划出</span>';
                        } else if(row.type == 2 ){
                            return '<span style="color: #b94a48">本级返还</span>';
                        } else if(row.type == 3 ){
                            return '<span style="color: orange">下级返还</span>';
                        } else if(row.type == 4 ){
                            return '<span style="color: purple">总后台撤机</span>';
                        } else if(row.type == 5 ){
                            return '<span style="color: purple">发货划入</span>';
                        } else if(row.type == 6 ){
                            return '<span style="color: purple">发货撤销</span>';
                        } else {
                            return '<span style="color: red">未知</span>';
                        }
                    },
                },
                {
                    field: 'total',
                    title: '台数'
                },
                {
                    field: 'serial',
                    title: '批次号',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,25);
                    }
                },
                {
                    field: 'addName',
                    title: '操作服务商名称'
                },
                {
                    field: 'addNo',
                    title: '操作服务商编号'
                },
                {
                    field: 'addTime',
                    title: '操作时间',
                    formatter:function (value, row, index) {
                        return row.addDate + " " + value;
                    }
                },
                {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="queryDetails(\''+row.serial+'\')"><i class="fa fa-plus"></i>查看详情</a> ');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        });
        function revoke() {
            var url =prefix+ "/revoke";
            $.modal.open("终端撤机" , url, '1200','600');
        }

        function downloada() {
            table.set();
            $.get(prefix+"/exportFile", function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            });
        }

        /**
         * 查看当前划拨批次机器详情
         * @param serial
         */
        function queryDetails(serial) {
            $.modal.openTab("批次详情", prefix + "/queryDetail?serial="+serial);
        }

    </script>
</body>
</html>